package data.preprocessing;


import net.sf.snowball.ext.englishStemmer;

/**
 * Applies the english stemmer on each word (of a String) which is bigger than 2 letters and less than 50 letters
 * @author guillaumes
 *
 */
public class PorterStemmer implements StringProcessor {

	protected englishStemmer stemmer;
	
	public PorterStemmer()
	{
		stemmer=new englishStemmer();
	}
	
	public String map(String from) {
		StringBuffer sb=new StringBuffer();
		String[] result = from.split("[^a-zA-Z0-9]+");
		
		for(int i=0;i<result.length;i++)
		{
			if ((result[i].length()<50) || (result[i].length()>2))
			{
				stemmer.setCurrent(result[i]);
				stemmer.stem();
				sb.append(stemmer.getCurrent());
				sb.append(" ");
			}
			else 
				sb.append(result[i]);
				sb.append(" ");
			
		}
		return(sb.toString());
	}

}
